
clear all;
close all;

A = { "gsl_steepest_descent", ...
      "gsl_conjugate_pr", ...
      "gsl_ext_bfgs_f", ...
      "gsl_ext_bfgs_mt", ...
      "gsl_ext_conjgrad_pr_mt" };

F = "(x^2 + y - 11)^2 + (x + y^2 - 7)^2";

X_MIN = { [ 3; 2 ], ...
          [ -3.78; -3.28 ], ...
          [ -2.81; 3.13 ], ...
          [ 3.58; -1.85 ] };

X = linspace(-5, 5, 30);
Y = linspace(-5, 5, 30);
COLORS = { "r", "g", "b", "c" };

for ai = 1:length(A)
  GSLpp_newplot();
  [ XC, YC, FXY ] = ...
  GSLpp_testfunction_data(F, struct(), 300, [ -5, 5 ], [ -5, 5 ]);
  contour(XC, YC, FXY, logspace(0, 5, 20));
  hold on;

  for y = Y
    for x = X
      x0 = [ x, y ]';
    
      results = GSLpp_minimize(A{ai}, struct, struct, ...
                               F, struct(), ...
                               struct("f", "sym", "g", "sym", "H", "sym"), ...
                               "gradient", struct("eps", 1e-8), ...
                               x0, 0, false);
      x_final = results.iterations{results.numiter}.x;
      
      for mi = 1:4
        if norm(x_final - X_MIN{mi}) < 1e-2
          break;
        endif
      endfor
    
      plot(x, y, [ '*', COLORS{mi} ], "markersize", 10);
    endfor
  endfor
    
  hold off;
  title(GSLpp_title(A{ai}));
  print([ "startingpoint_test_", A{ai}, ".ps" ], "-landscape", "-dashed", "-FArial:22");
  close;
endfor
